﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BibleBase
{
    [Serializable]
    public class Book
    {
        public string Name { get; set; }

        public Book()
        {
            Chapters = new List<Chapter>();
        }

        public Book(string name)
            : this()
        {
            Name = name;
        }

        public List<Chapter> Chapters { get; set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format("Libro: {0}", Name));
            sb.AppendLine();
            Chapters.ForEach(x => sb.AppendLine(x.ToString()));
            return sb.ToString();
        }

        private static int CompareChapters(Chapter a, Chapter b) { return a.Number - b.Number; }

        public void Sort()
        {
            Chapters.Sort(CompareChapters);
            foreach (Chapter chapter in Chapters)
            {
                chapter.Sort();
            }
        }
    }
}
